

#import "NSString+wordChange.h"

@implementation NSString (wordChange)

//汉字转换为拼音后，返回大写的首字母
- (NSString *)firstCharacterOfName
{
//    NSMutableString * first = [[NSMutableString alloc] initWithString:[self substringWithRange:NSMakeRange(0, 1)]];
    NSMutableString * first = [[NSMutableString alloc] initWithString:self];
//    NSString * first = self;
    CFRange range = CFRangeMake(0, self.length);
    
    // 汉字转换为拼音,并去除音调
    if ( ! CFStringTransform((__bridge CFMutableStringRef) first, &range, kCFStringTransformMandarinLatin, NO) ||
        ! CFStringTransform((__bridge CFMutableStringRef) first, &range, kCFStringTransformStripDiacritics, NO)) {
        return @"";
    }
    NSArray *array = [first componentsSeparatedByString:@" "];
    
    NSMutableString *address = [NSMutableString string];
    for (NSString *str in array) {
        [address appendString:str];
    }
    
    
//    NSString * result;
//    NSLog(@"%@",address);
//    result = [first substringWithRange:NSMakeRange(0, 1)];
    
    return address;
}

@end
